// utils/user-info.js
export const getUserInfo = () => {
  return new Promise((resolve, reject) => {
    if (typeof window.wx === 'undefined') {
      reject(new Error('微信环境不存在'))
      return
    }
    
    window.wx.ready(() => {
      window.wx.getUserInfo({
        success: (res) => {
          resolve({
            success: true,
            data: {
              nickName: res.userInfo.nickName,
              avatarUrl: res.userInfo.avatarUrl,
              gender: res.userInfo.gender,
              country: res.userInfo.country,
              province: res.userInfo.province,
              city: res.userInfo.city
            }
          })
        },
        fail: (err) => {
          reject(new Error(err.errMsg))
        }
      })
    })
  })
}